﻿Imports System.Data.Odbc

Public Class EXCELReferentielCRT
    Implements IReferentielCRT


    Dim _InfoTables As ObjectModel.ReadOnlyCollection(Of PTIC_Util.IInfoTableReferentiel)

    Shared tbls() As String = New String() {
        "TABLE_COMPTES",
        "TABLE_POSTES",
        "TABLE_DESCCOMPTES",
        "TABLE_REF_COASS",
        "TABLE_PLAN_COASS",
        "TABLE_REF_REASS",
        "TABLE_PLAN_REASS", _
        "TABLE_REF_CRT", _
        "TABLE_DATA_CRT"}

    Dim connectionstring As String

    Sub New(ByVal fichier As String)

        _InfoTables = New ObjectModel.ReadOnlyCollection(Of PTIC_Util.IInfoTableReferentiel)( _
                             tbls.Select(Function(t) CType(New EXCELInfoTableReferentiel(t), PTIC_Util.IInfoTableReferentiel)).ToList())
        connectionstring = "Dsn=Excel Files;dbq=" & fichier
    End Sub

    Public ReadOnly Property InfoTables As System.Collections.ObjectModel.ReadOnlyCollection(Of PTIC_Util.IInfoTableReferentiel) Implements Common.Model.Interfaces.IReferentiel.InfoTables
        Get
            Return _InfoTables
        End Get
    End Property

    Public ReadOnly Property IsReadonly As Boolean Implements IReferentielCRT.IsReadonly
        Get
            Return True
        End Get
    End Property

    Public Function SqlSelectQuery(ByVal queryString As String) As System.Data.DataTable Implements IReferentielCRT.SqlSelectQuery

        Dim adapter = New OdbcDataAdapter(queryString, connectionstring)

        Dim result = New Data.DataTable()

        adapter.Fill(result)

        Return result
    End Function
End Class
